
import allure

#导入该业务相关的UI类们
from page.page_index import PageIndex
from page.page_login import PageLogin
from page.page_user import PageUser

#登录业务
class LoginServer(object):

    def __init__(self,driver,base_url):
        self.driver=driver
        self.base_url=base_url

        #初始化相关的的页面对象们
        self.ui1=PageIndex(driver,base_url)
        self.ui2=PageLogin(driver,base_url)
        self.ui3=PageUser(driver,base_url)


    def service_login_01(self,d):
        #UI1页面的业务操作
        allure.attach("","打开首页")
        self.ui1.openUrl()
        allure.attach("", "点击首页的登录按钮")
        self.ui1.clickLogin()
        #UI2页面的业务操作
        allure.attach("", f"输入账号:{d['zanhao']}")
        self.ui2.inputZanhao(d["zanhao"])
        allure.attach("", f"输入密码:{d['pwd']}")
        self.ui2.inputPwd(d["pwd"])
        allure.attach("", "点击登录页的登录按钮")
        self.ui2.clickLogin()
        #UI3页面的业务操作
        siji=self.ui3.getNicenText()
        imgName=self.ui3.savePng3("登录业务",d["key"])
        allure.attach("", f"获取昵称:{siji}")
        allure.attach(open(f'./screen/{imgName}.png', 'rb').read(), "登录成功后截图", allure.attachment_type.PNG)
        return siji==d["yuqi"]

    def service_login_02(self,d):
        #UI1页面的业务操作
        self.ui1.openUrl()
        self.ui1.clickLogin()
        #UI2页面的业务操作
        self.ui2.inputZanhao(d["zanhao"])
        self.ui2.inputPwd(d["pwd"])
        self.ui2.clickLogin()
        siji=self.ui2.getErrorTipText()
        return d["yuqi"] in siji


    def service_login_03(self,d):
        #UI1页面的业务操作
        self.ui1.openUrl()
        self.ui1.clickLogin()
        #UI2页面的业务操作
        self.ui2.inputZanhao(d["zanhao"])
        self.ui2.inputPwd(d["pwd"])
        self.ui2.clickLogin()
        siji=self.ui2.getZanhaoClassAttr() #"input_text  invalid-text"
        return d["yuqi"] in siji

    def service_login_04(self,d):
        #UI1页面的业务操作
        self.ui1.openUrl()
        self.ui1.clickLogin()
        #UI2页面的业务操作
        self.ui2.inputZanhao(d["zanhao"])
        self.ui2.inputPwd(d["pwd"])
        self.ui2.clickLogin()
        siji=self.ui2.getPwdClassAttr()
        return d["yuqi"] in siji



